package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.ExpChangeBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.ExpChangeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.UserinfoUpdaterecord;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
/**
*经验值变动
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ExpChange{
	private static ExpChangeBean ExpChangeBean;
	private static ExpChangeCall ExpChangeCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("经验值变动");
	}

	@Before
	public void caseUp() {
		ExpChangeBean=new ExpChangeBean();
		ExpChangeCall=new ExpChangeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(ExpChangeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExpChange_001() {
		Logger.start(true,"经验值变动,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			ExpChangeBean.setExp(1);
			ExpChangeBean.setUserId(uid);
			ExpChangeBean.setLevel(1);
			ExpChangeCall.setData(ExpChangeBean);
			ExpChangeCall.callService();			
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(ExpChangeBean.getLevel(), ui.getUserLevel(), "验证userlevel");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExpChange_002() {
		Logger.start(true,"经验值变动等级提升,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			ExpChangeBean.setExp(1);
			ExpChangeBean.setUserId(uid);
			ExpChangeBean.setLevel(1);
			ExpChangeCall.setData(ExpChangeBean);
			ExpChangeCall.callService();		
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			Thread.sleep(1000);
			ExpChangeBean.setLevel(2);
			ExpChangeCall.callService();	
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(ExpChangeBean.getLevel(), ui.getUserLevel(), "验证userlevel");
			
			 UserinfoUpdaterecord uu = new JUserWapper().selectUserinfoUpdaterecord(uid).get(0);
			 Logger.verifyEquals(14,uu.getUserBizType(),"验证UserBizType等级变更");
			 Logger.verifyEquals("1",uu.getOldBizValue(),"验证旧等级变更");
			 Logger.verifyEquals("2",uu.getNewBizValue(),"验证新等级变更");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExpChange_003() {
		Logger.start(true,"经验值变动等级下降,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			ExpChangeBean.setExp(1);
			ExpChangeBean.setUserId(uid);
			ExpChangeBean.setLevel(2);
			ExpChangeCall.setData(ExpChangeBean);
			ExpChangeCall.callService();		
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			Thread.sleep(1000);
			ExpChangeBean.setExp(-100);
			ExpChangeBean.setLevel(1);
			ExpChangeCall.callService();	
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(ExpChangeBean.getLevel(), ui.getUserLevel(), "验证userlevel");
			
			 UserinfoUpdaterecord uu = new JUserWapper().selectUserinfoUpdaterecord(uid).get(0);
			 Logger.verifyEquals(14,uu.getUserBizType(),"验证UserBizType等级变更");
			 Logger.verifyEquals("2",uu.getOldBizValue(),"验证旧等级变更");
			 Logger.verifyEquals("1",uu.getNewBizValue(),"验证新等级变更");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExpChange_004() {
		Logger.start(false,"用户不存在,返回ok");
		try {
//			CreateUserReq cur = new CreateUserReq();
//			cur = JUserCallService.initCreateUserBean(cur);
//			cur.setMail(null);
//			Integer uid = JUserCallService.createUserCall(cur);
			
			ExpChangeBean.setExp(1);
			ExpChangeBean.setUserId(999999999);
			ExpChangeBean.setLevel(2);
			ExpChangeCall.setData(ExpChangeBean);
			ExpChangeCall.callService();		
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExpChange_005() {
		Logger.start(false,"用户小于0,返回ok");
		try {
//			CreateUserReq cur = new CreateUserReq();
//			cur = JUserCallService.initCreateUserBean(cur);
//			cur.setMail(null);
//			Integer uid = JUserCallService.createUserCall(cur);
			
			ExpChangeBean.setExp(1);
			ExpChangeBean.setUserId(-111);
			ExpChangeBean.setLevel(2);
			ExpChangeCall.setData(ExpChangeBean);
			ExpChangeCall.callService();		
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExpChange_006() {
		Logger.start(false,"不输入参数,返回ok,不做任何操作");
		try {
			ExpChangeCall.setData(ExpChangeBean);
			ExpChangeCall.callService();		
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExpChange_007() {
		Logger.start(false,"不输入等级,不做操作");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			ExpChangeBean.setExp(1);
			ExpChangeBean.setUserId(uid);
			ExpChangeBean.setLevel(2);
			ExpChangeCall.setData(ExpChangeBean);
			ExpChangeCall.callService();		
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			Thread.sleep(1000);
			ExpChangeBean.setExp(-100);
			ExpChangeBean.setLevel(null);
			ExpChangeCall.callService();	
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(2, ui.getUserLevel(), "验证userlevel");
			
			 UserinfoUpdaterecord uu = new JUserWapper().selectUserinfoUpdaterecord(uid).get(0);
			 Logger.verifyEquals(14,uu.getUserBizType(),"验证UserBizType等级变更");
			 Logger.verifyEquals("1",uu.getOldBizValue(),"验证旧等级变更");
			 Logger.verifyEquals("2",uu.getNewBizValue(),"验证新等级变更");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExpChange_008() {
		Logger.start(false,"输入等级小于1,不做操作");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			cur.setMail(null);
			Integer uid = JUserCallService.createUserCall(cur);
			
			ExpChangeBean.setExp(1);
			ExpChangeBean.setUserId(uid);
			ExpChangeBean.setLevel(2);
			ExpChangeCall.setData(ExpChangeBean);
			ExpChangeCall.callService();		
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			Thread.sleep(1000);
			ExpChangeBean.setExp(-100);
			ExpChangeBean.setLevel(0);
			ExpChangeCall.callService();	
			Logger.verifyEquals("ok", ExpChangeCall.getReturnData(), "验证Success");
			
			Logger.comment("验证Userinfo");
			Userinfo ui = new JUserWapper().selectUserinfoByUid(uid).get(0);
			Logger.verifyEquals(2, ui.getUserLevel(), "验证userlevel");
			
			 UserinfoUpdaterecord uu = new JUserWapper().selectUserinfoUpdaterecord(uid).get(0);
			 Logger.verifyEquals(14,uu.getUserBizType(),"验证UserBizType等级变更");
			 Logger.verifyEquals("1",uu.getOldBizValue(),"验证旧等级变更");
			 Logger.verifyEquals("2",uu.getNewBizValue(),"验证新等级变更");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}